package com.example.game;

import android.content.Context;
import android.util.Log;

import com.example.bounce.R;
import com.example.object.game.Ball;
import com.example.object.game.Chain;
import com.example.object.game.Wooden;
import com.example.object.screen.Background;
import com.example.object.GameShape;
import com.example.state.AppState;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;

import java.util.List;

/**
 * Created by Lucas on 28/06/13.
 */
public class Game {
    /**
     * Debug TAG
     */
    private final String TAG = "Game";
    /**
     * JBox2D World
     */
    private World _world;
    /**
     * Ratio between the JBox2D world and the screen
     */
    public final static float RATIO = AppState.SIMULATION_WIDTH /2f;
    /**
     * The difficulty of the world
     */
    private int _difficulty;
    /**
     * The world to play
     */
    private int _level;

    /**
     * create the game with a new workd
     */
    public Game(){
        Log.i(TAG, "Init game with -9.8 gravity");
        _world = new World(new Vec2(-9.8f,0f));
    }

    /**
     * Initialize the list of the game shape
     * @param listGameShape the list to initialize
     * @param context the context of the application
     */
    public void initGameShape(List<GameShape> listGameShape, Context context){
        // initialize shape
        listGameShape.add(new Background(context, AppState.SIMULATION_HEIGHT/2f, R.raw.backgroundhome));
        Ball ball = new Ball(context, 1.5f, 0.5f, 0.128f, 0.128f);

        //Wooden wooden = new Wooden(context, 1f, 0.5f, 0.1f, 0.5f);
        Wooden floor = new Wooden(context, 0.5f, 1f, 0.1f, 1f);
        Chain chain = new Chain(context, 1f, 2.5f, 0.5f);
        // add shape into the world
        ball.addToWorld(_world);
        //wooden.addToWorld(_world);
        floor.addToWorld(_world);

        chain.addToWorld(_world);
        // add the shape and object into the list
        listGameShape.add(ball);
        //listGameShape.add(wooden);
        listGameShape.add(floor);
        listGameShape.add(chain);
    }

    /**
     * Update the state of the world.
     */
    public void updateWorld(){
        int velocityIteration = 6;
        int positionIteration = 2;
        _world.step(1f/50f, velocityIteration, positionIteration);
    }

    public void initializeGame(int difficulty, int world) {
        _level = world;
        _difficulty = difficulty;
    }

    public World getWorld() {
        return _world;
    }
}
